<!-- Discuss_StudentList.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>学生端讨论列表</title>
    <link rel="stylesheet" href="../../css/mui.min.css"/>
    <link rel="stylesheet" href="../../css/base.css">
    <style type="text/css">
    	.mui-table-view-cell>a:not(.mui-btn){
    		padding: 10px;
    	}
    	.cell-subtitle,.message_content{
    		height: 16px;
    		line-height: 16px;
    	}
    	.right-div{
    		width: 48px;
    		float: right;
    	}
    	.left-div{
    		margin-right: 48px;
    	}
    	.message_title{
    		width: 90%;
    	}
    	.right-tag{
    		line-height: 42px;
    		text-align: right;
    	}
		.redPointMessage{
			top: 4px;
			left: 44px;
		}
		.hide-class{
			display: none;
		}
    </style>
</head>
<body>
	<ul id="discussList" class="mui-table-view">
		<!--<li class="mui-table-view-cell mui-media">
			<a href="javascript:;"  style="position:relative;" >
				<div id="tw_message"  class="redPointMessage"></div>
				<img class="mui-media-object mui-pull-left" src="../../image/icon_taolun1.png" >
				<div class="mui-media-body" >
					<div class="right-div">
						<p class='mui-ellipsis base_grey content_p right-tag'>
							未参与
						</p>
					</div>
					<div class="left-div">
						<p class="mui-ellipsis base_dark_grey font16 cell-title">
							<span class="message_title">
								讨论名称
							</span>
						</p>
						<p class='mui-ellipsis base_grey font14 content_p cell-subtitle'>
							<span class="message_content">
								<span class="file_submit_time">
									2017-01-02 14:20
								</span>
							</span>
						</p>
					</div>
				</div>
			</a>
		</li>-->
	</ul>
	<div class="noSign" hidden="hidden" id="noData">
		<img src="../../image/icon_img.png" width="60%">
		<p class="font16 top_15 base_dark_grey" >
			暂无数据
		</p>
	</div>
	<div class="loadFailure" hidden="hidden" id="noNet">
		<img src="../../image/icon_img01.png" width="60%">
		<p class="" >
			数据加载失败
		</p>
		<p>
			请检查您的网络
		</p>
		<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
			重新加载
		</button>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript">
	var page = 1;
	var rows = 10;
	var dropRefreshCount = 0;
	var discussDatas = new Array();
	var firstLoad = true;
	apiready = function(){
	    loadNewData();
		setRefreshHeader();
		setPullUpRefresh();
		setupNotifi();
		sendBuriedNotifi('1', '老师端讨论列表', '205')
	}
	function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
				cid : api.pageParam.cid,
			    pid : api.pageParam.pid
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
	function setupNotifi(){
		api.addEventListener({
		    name: 'pushMessage_classroomMessage'
		}, function(ret, err) {
		    // var id = ret.value.id;
		    // $('#redPoint'+id).removeClass('hide-class');
		    // $('#redPoint'+id).show();
		    var notifiJid = ret.value.jid;
		    //判断是否同一集团
		    if (notifiJid == $api.getStorage('cfnetppjxid')) {
		    	var type = ret.value.type;
			    if (type == 10011) {
			    	loadNewData();
			    }
		    }
		});
	}
	function loadNewData() {
		page = 1;
		loadData();
	}
	function loadMoreData() {
		page++;
		loadData();
	}
	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			loadNewData();
		});
	}
	// 上拉加载
	function setPullUpRefresh() {
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (dropRefreshCount >= rows) {
				dropRefreshCount = 0;
				loadMoreData();
			}
		});
	}
	function loadData(){
		if (firstLoad == true) {
			api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '加载中...',
			    text: '',
			    modal: false
			});
			firstLoad = false;
		}
		var param = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjxid'),
			page : page,
			rows : rows,
			tid : 4,
			cid : api.pageParam.cid,
			pid : api.pageParam.pid
		};
		cfnetppPOST(url_DiscussStuList, param, true, function(data, status){
			api.refreshHeaderLoadDone();
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					var disArr = data.data;
					if (disArr != null && disArr.constructor == Array && disArr.length > 0) {
						var currentIndex = discussDatas.length;
						dropRefreshCount = disArr.length;
						discussDatas = discussDatas.concat(disArr);
						var disHtmlString = new String();
						for (var i = currentIndex; i < discussDatas.length; i++) {
							var disData = discussDatas[i];
							disHtmlString += discussHtmlWithData(disData, i);
						}
						if (page == 1) {
							$('#discussList').html(disHtmlString);
						}else{
							$('#discussList').append(disHtmlString);
						}
						addCellClick();
						$('#noData').hide();
						$('#noNet').hide();
					}else{
						if (page == 1) {
							$('#discussList').html('');
							$('#noData').show();
							$('#noNet').hide();
						}
					}
				}else{
					if (page == 1) {
						$('#discussList').html('');
						$('#noData').show();
						$('#noNet').hide();
					}
				}
			}else{
				if (page > 1) {
					page--;
					dropRefreshCount = rows;
					api.toast({
						msg : '网络异常'
					});
				}else{
					$('#discussList').html('');
					$('#noData').hide();
					$('#noNet').show();
				}
			}
		});
	}
	function discussHtmlWithData(data, index){
		var starttime = data.starttime;
		var timeString = '';
		if (starttime == null||starttime == "0") {
			timeString = timeWithStamp3(data.createtime);
		}else{
			timeString = timeWithStamp3(starttime);
		}
		var new_message = "";
		var activestatus = data.activestatus;
		var statusString = '未开始';
		if(activestatus == 1){//已开始
			if (data.userstatus == 11) {//已参加
				statusString = '已参与';
			}else{
				statusString = '进行中';
				new_message = '<div id="redPoint'+ data.id + '" class="redPointMessage"></div>';
			}
		}else if(activestatus == 2){//已结束
			statusString = '已结束';
		}else if(activestatus == 3){//已删除
			// statusString = '已删除';
			statusString = '已结束';
		}
		
		var title = data.name;
		if (title == null || title == undefined) {
			title = data.NAME;
		}
		
		// var new_message = '<div id="redPoint'+ data.id + '" class="redPointMessage hide-class"></div>';
  //       var s = data.status;
		// if(s != undefined && s != null && s == 0){
  //           new_message = '<div id="redPoint'+ data.id + '" class="redPointMessage"></div>';
		// }

		return '<li id="'+data.id+'" class="mui-table-view-cell mui-media discuss-cell" index="'+index+'">'+
			'<a href="javascript:;" style="position:relative;" >'+
           		 new_message +
				'<img class="mui-media-object mui-pull-left" src="../../image/icon_taolun1.png" >'+
				'<div class="mui-media-body">'+
					'<div class="right-div">'+
						'<p class="mui-ellipsis base_grey content_p font12 right-tag">'+
							statusString+
						'</p>'+
					'</div>'+
					'<div class="left-div" >'+
						'<p class="mui-ellipsis base_black_grey font14 cell-title">'+
							'<span class="message_title">'+
								title+
							'</span>'+
						'</p>'+
						'<p class="mui-ellipsis base_grey font12 content_p cell-subtitle">'+
							'<span class="message_content">'+
								'<span class="file_submit_time">'+
									timeString+
								'</span>'+
							'</span>'+
						'</p>'+
					'</div>'+
				'</div>'+
			'</a>'+
		'</li>';
	}
	function addCellClick(){
		$('.discuss-cell').unbind('click');
		$('.discuss-cell').click(function(){
			var index = parseInt($(this).attr('index'));
            var disData = discussDatas[index];
            // uploadReadStatus(disData.id);
            // $("#redPoint"+disData.id).hide();
			disData["usertype"] = 'student';
			var title = disData.name;
			if (title == null || title == undefined) {
				title = disData.NAME;
			}
			disData["name"] = title;
			api.openWin({useWKWebView:true,
			    name: 'Discuss_TeacherDetailWin',
			    url: 'Discuss_TeacherDetailWin.html',
			    pageParam: disData
			});
		});
	}

	/*
	 修改课堂信息状态
	 */
    function uploadReadStatus(id){
        var params = {
            uid : $api.getStorage('cfnetppuid'),
            jid : $api.getStorage('cfnetppjxid'),
            iid : id,
			tid : 4
        };
        console.log(JSON.stringify(params));
        cfnetppPOST(url_classroomMessageSetStatus, params, false, function(data, status){});
    }

	function refreshData(){
		firstLoad = true;
		loadNewData();
	}
	function numNullStr(str){
		if (str == null || str == '' || str == undefined) {
			return 0;
		}
		return str;
	}
</script>
</html>